package com.bdzl.pub.util.ip;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Random;

public class ipUtils {

    public static void main(String[] args) {
        System.out.println(random(7));
    }

   public  static final String hostIp = getIp();

    /**
     * 获取本机ip
     * @return
     */
    public static String getIp(){

        InetAddress addr = null;
        try {
            addr = InetAddress.getLocalHost();
            System.out.println("Local HostAddress: "+addr.getHostAddress());
            String hostname = addr.getHostName();
            System.out.println("Local host name: "+hostname);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return addr.getHostAddress();
    }


    public static String random(int places) {
        StringBuilder num = new StringBuilder();
        Random ran = new Random();
        String new_nums = " ";
        for (int i = 0; i < places; i++) {
            StringBuilder nums = num.append(ran.nextInt(10));
            new_nums = nums.toString();
        }
        return new_nums;
    }




}
